/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.click.app.webapp.action;

import com.click.app.model.Laundry;
import com.click.app.model.PeriodPaymentLaundry;
import com.click.app.service.LaundryManager;
import com.click.app.service.PeriodPaymentLaundryManager;
import java.util.List;

/**
 *
 * @author ronald
 */
public class PeriodPaymentLaundryAction extends BaseAction {
    private Long id;
    private LaundryManager laundryManager;
    private Laundry laundry;

    private PeriodPaymentLaundry periodPaymentLaundry;
    private PeriodPaymentLaundryManager periodPaymentLaundryManager;
    private List<PeriodPaymentLaundry> periodPaymentLaundryList;

    public String choicedLaundryPeriod(){
        if(id == null)
            id = (Long)getSession().getAttribute("lPid");

        if (id != null){
            laundry = laundryManager.get(id);
            periodPaymentLaundryList = laundry.getPeriodPaymentLaundryList();
            getSession().setAttribute("lPid", laundry.getId());
        }
        return SUCCESS;
    }

    public String asignNewPeriodLaundry(){
        laundry = laundryManager.get((Long)getSession().getAttribute("lPid"));
        return SUCCESS;
    }
    public String saveNewperiodPaymentLaundry(){
        if(periodPaymentLaundry.getInitDate()!=null && periodPaymentLaundry.getInitAmount() >=0){
           laundry = laundryManager.get((Long)getSession().getAttribute("lPid"));
           periodPaymentLaundry.setClosed(false);
           periodPaymentLaundry.setLaundry(laundry);
           periodPaymentLaundryManager.save(periodPaymentLaundry);
           saveMessage(getText("periodPaymentLaundry.save"));
        }
        return SUCCESS;
    }
    public String reviewPeriodLaundryPayment(){
        
        return SUCCESS;
    }
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Laundry getLaundry() {
        return laundry;
    }

    public void setLaundry(Laundry laundry) {
        this.laundry = laundry;
    }

    public LaundryManager getLaundryManager() {
        return laundryManager;
    }

    public void setLaundryManager(LaundryManager laundryManager) {
        this.laundryManager = laundryManager;
    }

    public PeriodPaymentLaundry getPeriodPaymentLaundry() {
        return periodPaymentLaundry;
    }

    public void setPeriodPaymentLaundry(PeriodPaymentLaundry periodPaymentLaundry) {
        this.periodPaymentLaundry = periodPaymentLaundry;
    }

    public PeriodPaymentLaundryManager getPeriodPaymentLaundryManager() {
        return periodPaymentLaundryManager;
    }

    public void setPeriodPaymentLaundryManager(PeriodPaymentLaundryManager periodPaymentLaundryManager) {
        this.periodPaymentLaundryManager = periodPaymentLaundryManager;
    }

    public List<PeriodPaymentLaundry> getPeriodPaymentLaundryList() {
        return periodPaymentLaundryList;
    }

    public void setPeriodPaymentLaundryList(List<PeriodPaymentLaundry> periodPaymentLaundryList) {
        this.periodPaymentLaundryList = periodPaymentLaundryList;
    }
    
}
